﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLFacade.entities;
using BLFacade.enums;

namespace BL
{
    public partial class Task : ITask
    {

        public List<Nullable<DateTime>> ResolveDates
        {
            get
            {
                return TaskDates.Select(x => x.ResolveDate).ToList<Nullable<DateTime>>();
            }
        }

        public List<DateTime> StartDates
        {
            get
            {
                return TaskDates.Select(x => x.StartDate).ToList<DateTime>();
            }
        }

        TaskPriority ITask.Priority
        {
            get
            {
                return (TaskPriority)Priority;
            }
            set
            {
                Priority = (int)value;
            }
        }

        TaskStatus ITask.Status
        {
            get
            {
                return (TaskStatus)Status;
            }
            set
            {
                Status = (int)value;
            }
        }

        public void Start()
        {
            TaskDates.Add(new TaskDate() { StartDate = DateTime.Now });
            Status = (int)TaskStatus.InProgress;
        }

        public void Resolve()
        {
            TaskDates.Last<TaskDate>().ResolveDate = DateTime.Now;
            Status = (int)TaskStatus.Resolved;
        }


        IEmployee ITask.Employee
        {
            get
            {
                return (IEmployee)(this.Employee);
            }
            set
            {
                this.Employee = (Employee)value;
            }
        }

        IProject ITask.Project
        {
            get
            {
                return (IProject)(this.Project);
            }
            set
            {
                this.Project = (Project)value;
            }
        }

        public void Close(bool close)
        {
            CloseDate = DateTime.Now;
            Status = close ? (int)TaskStatus.Closed : (int)TaskStatus.Canceled;
        }

        public void Reopen()
        {
            Status = (int)TaskStatus.Reopened;
        }
    }
}
